<?php
/**
 * @property $data
 * @property $_templateEngine
 * 
 * View 基础抽象类
 */


class View {
    const RENDER_NONE = 'RENDER_NONE';
    const RENDER_HTML = 'RENDER_HTML';
    const RENDER_XML = 'RENDER_XML';

    public static $data = array();
    /**
     * @var Serpent
     * @var Smarty
     */
    protected $_templateEngine;
    
    public function __construct ($classname) {
        $this->_templateEngine = new $classname();    
    }
    
    public function pass ($vars) {
        if (is_array($vars)) {
            self::$data = $vars;
        } else {
            throw new View_Exception('Parameter for View::pass should be an Array');
        }
    }

    public function display($tpl){
        if (empty($tpl)) {
            throw new View_Exception('Template must NOT be empty!');
        }
        $tpl = explode('/', $tpl);
        $tpl = array_map('strtolower', $tpl);
        $tpl = implode('/', $tpl);
        
        $this->_templateEngine->assign(self::$data);
        $this->_templateEngine->display($tpl);

    }

}
?>